<template>
  <div class="login-panel">
    <!-- tab区域 -->
    <h1 class="title">教学选课管理系统</h1>
    <!-- 表单区域 -->
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="currentTab">
      <el-tab-pane name="student">
        <template #label>
          <span class="custom-tabs-label">
            <span>学生</span>
          </span>
        </template>
        <LoginStudent ref="studentRef" />
      </el-tab-pane>
      <el-tab-pane name="teacher">
        <template #label>
          <span class="custom-tabs-label">
            <span>教师</span>
          </span>
        </template>
        <LoginTeacher ref="teacherRef" />
      </el-tab-pane>
      <el-tab-pane name="admin">
        <template #label>
          <span class="custom-tabs-label">
            <span>管理员</span>
          </span>
        </template>
        <LoginAdmin ref="adminRef" />
      </el-tab-pane>
      <!-- 验证码 -->
      <Varify ref="varifyRef" />
      <!-- 功能区域 -->
      <div class="account-control">
        <el-checkbox v-model="isKeepPassword">记住密码</el-checkbox>
        <el-link type="primary" href="javascript:;" @click="reset">重置表单</el-link>
      </div>
      <!-- 登录 -->
      <!-- <el-button type="primary" class="login-btn" @click="handleLoginClick">登录</el-button> -->
      <el-button type="primary" class="login-btn" @click="handleLoginClick"> 登录 </el-button>
    </el-tabs>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { binMsg } from '@/global/api.js'
import LoginAdmin from './admin-login.vue'
import LoginTeacher from './teacher-login.vue'
import LoginStudent from './student-login.vue'
import Varify from './Varify.vue'
import { usePanelLogin } from '@/hooks/login.js'

const isKeepPassword = ref(false)
const currentTab = ref('student')
const studentRef = ref(null)
const teacherRef = ref(null)
const adminRef = ref(null)
const varifyRef = ref(null)

// 登录事件：检查账号密码 -> 检查验证码 -> 开始发起登录请求
const handleLoginClick = () => {
  binMsg().closeAll()
  if (currentTab.value === 'admin') {
    usePanelLogin(adminRef, varifyRef, isKeepPassword)
  } else if (currentTab.value === 'teacher') {
    usePanelLogin(teacherRef, varifyRef, isKeepPassword)
  } else {
    usePanelLogin(studentRef, varifyRef, isKeepPassword)
  }
}

// 重置
const reset = () => {
  if (currentTab.value === 'admin') {
    adminRef.value.reset()
  } else if (currentTab.value === 'teacher') {
    teacherRef.value.reset()
  } else {
    studentRef.value.reset()
  }
  varifyRef.value.inputCode = ''
}
</script>

<style lang="less" scoped>
.login-panel {
  margin-bottom: 100px;
  // margin-right: -800px;
  width: 380px;
  .title {
    text-align: center;
    letter-spacing: 3px;
    // font-family: 'Times New Roman', Georgia, serif;
    font-size: 35px;
    color: transparent;
    background: -webkit-linear-gradient(30deg, #32c5ff 25%, #b620e0 50%, #f7b500 75%, #20e050 100%);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-size: auto;
  }
  @keyframes gradientText {
    0% {
      background-position: 0;
    }
    100% {
      background-position: 28000px;
    }
  }
  .title {
    animation: gradientText 300s infinite linear;
    -webkit-animation: gradientText 300s infinite linear;
  }
  .account-control {
    display: flex;
    justify-content: space-between;
    margin-top: 17px;
  }
  .login-btn {
    margin-top: 17px;
    width: 100%;
    height: 40px;
  }
}
/deep/.el-tabs--border-card > .el-tabs__content {
  padding: 15px;
  padding-top: 25px;
  height: 290px;
}
</style>
